package com.example.demoboot.controller;

import com.example.demoboot.meiju.CurrencyEnum;
import com.example.demoboot.meiju.CurrencyEnum2;
import com.example.demoboot.meiju.CurrencyEnumList;
import com.example.demoboot.model.ChengBenVo;
import com.example.demoboot.model.XiaLaVo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
public class TestController {
    //枚举解决了
//    第一个问题：代码中不能存在魔法字符的问题！统一管理中文信息
    //第二个：解决了下拉框问题

    //代码优化：1.代码中不能存在魔法字符
    //2.for循环不能操作数据库，必须批量操作，占用连接量  mysql最大连接量2000左右
    //3.代码不能超过50行，必须会重构代码

    @GetMapping("testXiaLa")
    public List<XiaLaVo> test(){
        List<XiaLaVo> xiaLaVoList = new ArrayList<>();
        XiaLaVo xiaLaVo = new XiaLaVo();
        xiaLaVo.setLabel(CurrencyEnum.RENMINBI.getCurrency());
        xiaLaVo.setValue(CurrencyEnum2.RENMINBI.getCurrency());
        xiaLaVoList.add(xiaLaVo);
        XiaLaVo xiaLaVo2 = new XiaLaVo();
        xiaLaVo2.setLabel(CurrencyEnum.MEIYUAN.getCurrency());
        xiaLaVo2.setValue(CurrencyEnum2.MEIYUAN.getCurrency());
        xiaLaVoList.add(xiaLaVo2);
        return xiaLaVoList;
    }
    @GetMapping("testXiaLa2")
    public List<XiaLaVo> test2(){
        List<XiaLaVo> xiaLaVoList = new ArrayList<>();
        XiaLaVo xiaLaVo = new XiaLaVo();
        xiaLaVo.setLabel(CurrencyEnumList.RENMINBI.getCurrency());
        xiaLaVo.setValue(CurrencyEnumList.RENMINBI.getValue());
        xiaLaVoList.add(xiaLaVo);
        return xiaLaVoList;
    }
    @GetMapping("testXiaLa3")
    public List<XiaLaVo> test3(){
        List<XiaLaVo> xiaLaVoList = new ArrayList<>();
       for (CurrencyEnumList cr : CurrencyEnumList.values()){
           XiaLaVo xiaLaVo = new XiaLaVo(cr.getCurrency(),cr.getValue());
           xiaLaVoList.add(xiaLaVo);
       }
        return xiaLaVoList;
    }
    @GetMapping("testXiaLa4")
    public List<ChengBenVo> test4(){
      List<ChengBenVo> chengBenVos = new ArrayList<>();
        ChengBenVo chengBenVo = new ChengBenVo();
        chengBenVo.setId(1);
        chengBenVo.setCurrency(1);
        chengBenVo.setName("测试");
        chengBenVos.add(chengBenVo);
        for (ChengBenVo chengBenVo1: chengBenVos){
            /*if (chengBenVo1.getCurrency()==1){
                chengBenVo1.setCurrencyName("人民币");
            }*/
            chengBenVo1.setCurrencyName(CurrencyEnumList.MEIYUAN.getCurrencyName(chengBenVo1.getCurrency()));
        }

        return chengBenVos;
    }
}
